<?php
/**
 * Created by PhpStorm.
 * User: wangwenshan
 * Date: 2019/1/16
 * Time: 15:52
 */

namespace app\api\controller\v1;

use app\api\model\Banner as BannerModel;
use app\api\validate\IDMustBePositiveInt;
use app\lib\exception\BannerMissException;

class Banner
{
    /*
     * 获取指定id的banner信息
     * @url /banner/:id
     * @http GET
     * $id banner的id号
     * */
    public function getBanner($id){
        /*
         * 独立验证
         * */

        (new IDMustBePositiveInt())->getCheck();
//        $banner = BannerModel::with(['items','items.img'])->find($id);
        $banner = BannerModel::getBannerByID($id);
//        $banner->hidden(['update_time','delete_time']);
//        $data = $banner->toArray();
//        unset($data['delete_time']);
//        $banner = new BannerModel();
//        $banner = $banner->get($id);

        if(!$banner){
            throw new BannerMissException();
        }
        return $banner;
    }
}